/**   
 * Copyright © 2019 eSunny Info. Tech Ltd. All rights reserved.
 * 
 * @Description:TODO(功能)
 * @className CharacterFilter.java
 * @Package: com.erp.filter 
 * @author: yj   
 * @date: 2019年2月19日 上午9:05:14 
 */
package com.erp.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * @className CharacterFilter.java
 * @author yj
 * @Description:TODO(功能)
 * @Date 2019年2月19日
 */
public class CharacterFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("--- 字符乱码拦截器初始化 ---");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {

		// 解决中文了乱码
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;UTF-8");
		
		// 拦截器链
		chain.doFilter(request, response);
		
	}

	@Override
	public void destroy() {
		System.out.println("--- 字符乱码拦截器销毁---");

	}

}
